package com.month.ai.config;

import com.month.ai.advisors.DatabaseChatMemory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonConfig {


    //会话记忆配置---定义会话存储方式
    @Bean
    public ChatMemory chatMemory(){
        return new InMemoryChatMemory();

//        return new DatabaseChatMemory();
    }




    @Bean
    public ChatClient ChatClient(OpenAiChatModel model, ChatMemory chatMemory){
        return ChatClient.builder(model)
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(), //日志环绕
                        new MessageChatMemoryAdvisor(chatMemory) //会话记忆
                ).defaultTools("test")
                .build();
    }



}
